package com.lindenvalley.de.content;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;



@Root(strict=false)
public class Sections {

	//TODO Это для листа
	@ElementList(inline=true)
	private List<Section> section;

	/**
	 * @param section the section to set
	 */
	public void setSection(List<Section> section) {
		this.section = section;
	}

	/**
	 * @return the section
	 */
	public List<Section> getSection() {
		return section;
	}
	
	public Section getSectionById(int id){
		Section result = null;
		for(Section s :section){
			if (s.getId() == id)
				result = s;
		}
		return result;
	}
	
	public boolean hasSection(int sectionId){
		boolean result = false;
		for(Section s :section){
			if (s.getId() == sectionId){
				result = true;
				break;
			}
		}
		return result;
		
	}
	
	public int getAllQuestionSize(){
		int questionSize = 0;
		if (section != null){
			for(Section s :section){
				List<Question> questions = s.getQuestion();
				if (questions != null)
					questionSize += questions.size();
			}
		}
		return questionSize;
	}
	public List<Question> getAllQuestion(){
		List<Question> questions = new ArrayList<Question>();
		for(Section s :section){
			if (s.getQuestion() != null){
				for (Question q: s.getQuestion()){
					q.setSectionId(s.getId());
					questions.add(q);
				}
				
			}
		}
		return questions;
		
	}


}
